package com.edward.service;


import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.edward.PagerModel;
import com.edward.model.StatAc;


public class StatAcManager extends HibernateDaoSupport {

	public void addStatAc(StatAc statAc) {
		
		getHibernateTemplate().save(statAc);
	}
	
	public void updateStatAc(StatAc statAc) {
		
		getHibernateTemplate().update(statAc);
	}
	
	public void deleteStatAc(int id){
		
		getHibernateTemplate().delete(getStatAc(id));
	}
	
	public StatAc getStatAc(int id){
		StatAc d =(StatAc)getHibernateTemplate().get(StatAc.class, id);
		return d;
	}
	

	@SuppressWarnings("unchecked")
	public List<StatAc> listStatAc() {
		return getHibernateTemplate().find("from StatAc");
	}

	
	
	@SuppressWarnings("unchecked")
	public PagerModel pagerStatAc(int start,int limit,int id) {
		List <StatAc>list = getHibernateTemplate().find("from StatAc i  where STAT_ID = " + id );
		StatAc s = new StatAc();
		s.setCode("合计");
		for (StatAc statAc : list) {
			s.setMoney(s.getMoney() + statAc.getMoney());
			s.setBail(s.getBail() + statAc.getBail());
		}
		list.add(s);
		int total = list.size();
		int toIndex = start + limit;
		if(toIndex>total){
			toIndex =  total;
		}
		List <StatAc>datas = list.subList(start, toIndex);
		PagerModel pm = new PagerModel();
		pm.setTotal(total);
		pm.setDatas(datas);
		return pm;
		
	}
	


}



